import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:sports_new/base/base_controller.dart';
import 'package:sports_new/server/api/expert_api.dart';
import 'package:sports_new/utils/utils.dart';
import '../../../entity/expert/plan_pack/plan_pack_entity.dart';

class PlanPackHistoryLogic extends BaseController{
  String? expertId;
  List<PlanPackEntity>? data;
  int _page = 1;
  int pageSize = 15;

  int get page => _page;

  set page(int value) {
    _page = value;
    update();
  }

  @override
  void onInit() {
    expertId = Get.arguments;
    update();
    super.onInit();
  }

  @override
  void onReady() {
    getRefresh();
    super.onReady();
  }

  Future<List<PlanPackEntity>> getData() async {
    return await ExpertApi.getPlanPackHistory(page,pageSize,expertId:expertId);
  }

  @override
  void getRefresh() async{
    page = 1;
    data = await getData();
    update();
    super.getRefresh();
  }

  @override
  void loadMore() async{
    page += 1;
    var list = await getData();
    if(list.hasValue) data?.addAll(list);
    refreshController.finishLoad(
      (data?.length??0)<page*pageSize?IndicatorResult.noMore:IndicatorResult.success
    );
    update();
    super.loadMore();
  }
}